package com.guagua.blog.controller;

import com.guagua.blog.entity.Tag;
import com.guagua.blog.service.TagService;
import com.guagua.common.response.Result;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 使用完整类名
@io.swagger.v3.oas.annotations.tags.Tag(name = "标签管理", description = "标签相关接口")
@RestController
@RequestMapping("/api/tags")
@RequiredArgsConstructor
public class TagController {
    
    private final TagService tagService;
    
    @GetMapping
    @Operation(summary = "获取所有标签")
    public Result<List<Tag>> getAllTags() {
        return Result.success(tagService.list());
    }
    
    @PostMapping
    @Operation(summary = "创建标签")
    public Result<Tag> createTag(@RequestBody Tag tag) {
        tagService.save(tag);
        return Result.success(tag);
    }
    
    @DeleteMapping("/{id}")
    @Operation(summary = "删除标签")
    public Result<Void> deleteTag(@PathVariable Long id) {
        tagService.removeById(id);
        return Result.success();
    }
    
    @PutMapping("/{id}")
    @Operation(summary = "更新标签")
    public Result<Tag> updateTag(@PathVariable Long id, @RequestBody Tag tag) {
        tag.setId(id);
        tagService.updateById(tag);
        return Result.success(tag);
    }
} 